package tech.yunjing.train.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import tech.yunjing.train.entity.ReceiveRedPacketRecord;
import tech.yunjing.train.service.ReceiveRedPacketRecordService;
import tech.yunjing.train.util.JsonResult;

import java.util.List;

/**
 * 红包记录controller
 * Created by zlc on 2017/6/10.
 */
@RestController
    @RequestMapping("/record")
public class ReceiveRedPacketRecordController extends BaseController {

    @Autowired
    private ReceiveRedPacketRecordService receiveRedPacketRecordService;

    /**
     * 通过用户账户查询所有的抢红包记录
     *
     * @param userAccount 用户账户
     * @return 该用户所有的抢红包记录
     */
    @RequestMapping(value = "findAll", method = RequestMethod.POST)
    public JsonResult<List<ReceiveRedPacketRecord>> findByUserAccount(String userAccount) {
        List<ReceiveRedPacketRecord> list = receiveRedPacketRecordService.findByUserAccount(userAccount);
        return new JsonResult<List<ReceiveRedPacketRecord>>(list);
    }

    /**
     * 通过用户账户删除用户抢红包记录
     *
     * @param userAccount 用户账户
     * @return 删除的记录数量
     */
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public JsonResult<Integer> logicDelete(String userAccount) {
        return new JsonResult<Integer>(receiveRedPacketRecordService.logicDelete(userAccount));
    }


}
